package com.example.evanproject.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.example.evanproject.domain.Register;
import com.example.evanproject.domain.UserVo;
import com.example.evanproject.service.impl.RegisterServiceImpl;
import com.example.evanproject.util.AjaxResult;
import com.example.evanproject.util.ReturnsData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/login")
public class RegisterController {

    @Autowired
    private RegisterServiceImpl registerService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
     //获取验证码
    @RequestMapping("/getcode")
    public AjaxResult getcode(String phonenum){
     ReturnsData returnsData =  registerService.getcode(phonenum);
     //将获取到的验证码存入redis里面
        //将消息和验证码
        stringRedisTemplate.opsForValue().set(phonenum,returnsData.getData().toString());
        System.out.println("手机验证吗为");
        System.out.println("-----------------------------------------------");
        System.out.println(returnsData.getData().toString());
        System.out.println("-----------------------------------------------");
        return  AjaxResult.success(registerService.getcode(phonenum));
    }


//    注册
    @PostMapping("/register")
    public AjaxResult register(String phonenum,String code,String password,Integer sign){
        return AjaxResult.success(registerService.register(phonenum,code,password,sign));
    }

    //登录 (如果是新用户的时候,提示您的用户为新用户，先去注册)

    @PostMapping("/login")
    public AjaxResult login(String phonenum,String password,String code){
        return AjaxResult.success(registerService.login(phonenum,password,code));
    }








//    修改个人信息
//    public  ReturnsData modifyinfo(){
//
//    }


//    查询用户返回指定用户
    @RequestMapping("/selectbyid")
    public AjaxResult selectById(Integer id){
        System.out.println(registerService.selectById(id));
        return AjaxResult.success(registerService.selectById(id)) ;
    }


//    上传图片

    @PostMapping("upload")
    public AjaxResult upLoad(@ModelAttribute UserVo uservo) {
//        System.out.println("0000000");
//        System.out.println(file);
//        System.out.println(name);
//        System.out.println(age);
//        System.out.println(sex);

//        return AjaxResult.success(registerService.updateinfo(uservo.getName()name,age,sex,file,id));
return AjaxResult.success();

    }


    /*统计注册每年的人数*/
    @RequestMapping("getCountNum")
    public AjaxResult countNum(String year){
   return AjaxResult.success(registerService.countNum(year)) ;
    }

//    获取所有的用户信息
@RequestMapping("selectAllListInfo")
public R<IPage<Register>> selectAllLIstInfo(Register register){
     return registerService.selectAllLIstInfo(register);
}

}
